package com.macro.sms.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2配置
 *
 * @author xiaohai
 * @since 1.0.0
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    //api接口包扫描路径
    private static final String SWAGGER_SCAN_BASE_PACKAGE = "com.macro.sms.controller";

    private static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为当前包下的controller生成api文档
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        //设置文档信息
        return new ApiInfoBuilder() .title("阿里云手机短信获取接口文档")
                .description("阿里云手机短信获取接口文档")
                .contact(new Contact("小海", "http:localhost:8001/doc.html", "xxxx@xxxx.com"))
                .version(VERSION)
                .build();
    }


}
